package pkg;

import java.io.IOException;

import javax.servlet.http.HttpSession;

import com.google.gdata.util.ServiceException;

public class Menu implements java.io.Serializable {
	public static String printMenu(HttpSession session){
		StringBuffer out = new StringBuffer();
		if (session.getAttribute("user")!=null){
			out.append("<li id=\"menu-01\"><a href=\"kontakty.jsp?wybor=lista\">Lista kontaktów</a></li>\n");
			out.append("<li id=\"menu-02\"><a href=\"kontakty.jsp?wybor=nowy\">Nowy kontakt</a></li>\n");
			out.append("<li id=\"menu-03\"><a href=\"kontakty.jsp?wybor=lgrupy\">Lista grup</a></li>\n");
			out.append("<li id=\"menu-04\"><a href=\"kontakty.jsp?wybor=ngrupy\">Nowa grupa</a></li>\n");
		
			out.append("<p></p>");
			out.append("<li id=\"menu-07\"><a href=\"regulamin.jsp\">Regulamin</a></li><li id=\"menu-08\"><a href=\"kontakt.jsp\">Kontakt</a></li>");
		}
		return out.toString(); 
	}
	
	public static String printList(HttpSession session){
		StringBuffer out = new StringBuffer();
		Kontakty kontakt = (Kontakty)session.getAttribute("Kontakty");
		if (kontakt!=null){
			try {
				out.append("<h2>Lista kontaktów</h2>\n<p></p>\n");
				out.append(kontakt.printAllContacts(kontakt.getSerwis(), kontakt.getUser()));
			}
			catch (ServiceException e){
				return "<h2>Blad polaczenia</h2>";
			}
			catch (IOException e){
				return "<h2>Blad polaczenia</h2>";
			}
		}
		return out.toString();
	}
	public static String printContactForm(HttpSession session){
		StringBuffer out = new StringBuffer();
		Kontakty kontakt = (Kontakty)session.getAttribute("Kontakty");
		if (kontakt!=null){
			out.append("<h2>Nowy kontakt</h2>\n<p></p>\n");
			
			out.append("<FORM METHOD=POST ACTION=\"kontakty.jsp?wybor=nowy2\">");
			out.append("<TABLE>");
			out.append("<TR>");
				out.append("<TD width = 100>Nazwa:</TD>");
				out.append("<TD><INPUT TYPE=TEXT NAME=name SIZE=20></TD>");
			out.append("</TR>");
			out.append("<TR>");
				out.append("<TD>E-mail:</TD>");
				out.append("<TD><INPUT TYPE=TEXT NAME=email SIZE=20></TD>");
			out.append("</TR>");
			out.append("</TABLE>");
			out.append("<P align=\"center\"><INPUT TYPE=submit value=\"Dodaj\"></P>");
			out.append("</FORM>");
			
			
		}
		return out.toString();
	}
	
	// ====================================== GRUPY ================================
	public static String printGroupsList(HttpSession session){
		Kontakty kontakt = (Kontakty) session.getAttribute("Kontakty");
		if (kontakt == null) return "<h2> Blad </h2>";
		
		return kontakt.printAllGroups(kontakt.getSerwis());
	}
	
	public static String printGroupForm(HttpSession session){
		StringBuffer out = new StringBuffer();
		
		out.append("<h2>Nowa grupa</h2>\n<p></p>\n");
		
		out.append("<FORM METHOD=POST ACTION=\"kontakty.jsp?wybor=ngrupy2\">");
		out.append("<TABLE>");
		out.append("<TR>");
			out.append("<TD width = 100>Nazwa:</TD>");
			out.append("<TD><INPUT TYPE=TEXT NAME=name SIZE=20></TD>");
		out.append("</TR>");
		out.append("</TABLE>");
		out.append("<P align=\"center\"><INPUT TYPE=submit value=\"Dodaj\"></P>");
		out.append("</FORM>");
		
		return out.toString();
	}
}
